Fix CupertinoListTile`s onTap with delay throws exception (#109038)
This commit is contained in:
@@ -385,7 +385,9 @@ class _CupertinoListTileState extends State<CupertinoListTile> {
|
||||
onTapCancel: () => setState(() { _tapped = false; }),
|
||||
onTap: () async {
|
||||
await widget.onTap!();
|
||||
setState(() { _tapped = false; });
|
||||
if (mounted) {
|
||||
setState(() { _tapped = false; });
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: child,
|
||||
|
||||
@@ -479,4 +479,44 @@ void main() {
|
||||
expect(foundInfo.dx > foundTrailing.dx, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('onTap with delay does not throw an exception', (WidgetTester tester) async {
|
||||
const Widget title = Text('CupertinoListTile');
|
||||
bool showTile = true;
|
||||
|
||||
Future<void> onTap() async {
|
||||
showTile = false;
|
||||
await Future<void>.delayed(
|
||||
const Duration(seconds: 1),
|
||||
() => showTile = true,
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildCupertinoListTile() {
|
||||
return CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
if (showTile)
|
||||
CupertinoListTile(
|
||||
onTap: onTap,
|
||||
title: title,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(buildCupertinoListTile());
|
||||
expect(showTile, isTrue);
|
||||
await tester.tap(find.byType(CupertinoListTile));
|
||||
expect(showTile, isFalse);
|
||||
await tester.pumpWidget(buildCupertinoListTile());
|
||||
await tester.pumpAndSettle(const Duration(seconds: 5));
|
||||
expect(tester.takeException(), null);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user