Unverified Commit 4e2b6480 authored by xubaolin's avatar xubaolin Committed by GitHub

[Dismissible]Fix a state lose issue (#108971)

parent 4293ce9a
......@@ -323,6 +323,8 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
Size? _sizePriorToCollapse;
bool _dismissThresholdReached = false;
final GlobalKey _contentKey = GlobalKey();
@override
bool get wantKeepAlive => (_moveController?.isAnimating ?? false) || (_resizeController?.isAnimating ?? false);
......@@ -668,7 +670,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
Widget content = SlideTransition(
position: _moveAnimation,
child: widget.child,
child: KeyedSubtree(key: _contentKey, child: widget.child),
);
if (background != null) {
......
......@@ -329,6 +329,7 @@ void main() {
' PhysicalModel\n'
' AnimatedPhysicalModel\n'
' Material\n'
' KeyedSubtree-[GlobalKey#00000]\n'
' FractionalTranslation\n'
' SlideTransition\n'
' Listener\n'
......
......@@ -1150,4 +1150,32 @@ void main() {
expect(reportedDismissUpdatePreviousReached, false);
expect(reportedDismissUpdateProgress, 0.0);
});
testWidgets('Change direction does not lose child state', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/108961
Widget buildFrame(DismissDirection direction) {
return Directionality(
textDirection: TextDirection.ltr,
child: Dismissible(
dragStartBehavior: DragStartBehavior.down,
direction: direction,
key: const Key('Dismissible'),
resizeDuration: null,
child: const SizedBox(
width: 100.0,
height: 100.0,
child: Text('I Love Flutter!'),
),
),
);
}
await tester.pumpWidget(buildFrame(DismissDirection.horizontal));
final RenderBox textRenderObjectBegin = tester.renderObject(find.text('I Love Flutter!'));
await tester.pumpWidget(buildFrame(DismissDirection.none));
final RenderBox textRenderObjectEnd = tester.renderObject(find.text('I Love Flutter!'));
expect(identical(textRenderObjectBegin, textRenderObjectEnd), true);
});
}
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