[Dismissible]Fix a state lose issue (#108971)
This commit is contained in:
parent
4293ce9a5c
commit
4e2b648069
@ -323,6 +323,8 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
|
|||||||
Size? _sizePriorToCollapse;
|
Size? _sizePriorToCollapse;
|
||||||
bool _dismissThresholdReached = false;
|
bool _dismissThresholdReached = false;
|
||||||
|
|
||||||
|
final GlobalKey _contentKey = GlobalKey();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => (_moveController?.isAnimating ?? false) || (_resizeController?.isAnimating ?? false);
|
bool get wantKeepAlive => (_moveController?.isAnimating ?? false) || (_resizeController?.isAnimating ?? false);
|
||||||
|
|
||||||
@ -668,7 +670,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
|
|||||||
|
|
||||||
Widget content = SlideTransition(
|
Widget content = SlideTransition(
|
||||||
position: _moveAnimation,
|
position: _moveAnimation,
|
||||||
child: widget.child,
|
child: KeyedSubtree(key: _contentKey, child: widget.child),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (background != null) {
|
if (background != null) {
|
||||||
|
@ -329,6 +329,7 @@ void main() {
|
|||||||
' PhysicalModel\n'
|
' PhysicalModel\n'
|
||||||
' AnimatedPhysicalModel\n'
|
' AnimatedPhysicalModel\n'
|
||||||
' Material\n'
|
' Material\n'
|
||||||
|
' KeyedSubtree-[GlobalKey#00000]\n'
|
||||||
' FractionalTranslation\n'
|
' FractionalTranslation\n'
|
||||||
' SlideTransition\n'
|
' SlideTransition\n'
|
||||||
' Listener\n'
|
' Listener\n'
|
||||||
|
@ -1150,4 +1150,32 @@ void main() {
|
|||||||
expect(reportedDismissUpdatePreviousReached, false);
|
expect(reportedDismissUpdatePreviousReached, false);
|
||||||
expect(reportedDismissUpdateProgress, 0.0);
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user