Unverified Commit f4a64ef0 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `CupertinoListTile``s onTap with delay throws exception (#109038)

parent 3bc49103
......@@ -385,7 +385,9 @@ class _CupertinoListTileState extends State<CupertinoListTile> {
onTapCancel: () => setState(() { _tapped = false; }),
onTap: () async {
await widget.onTap!();
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);
});
}
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