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

This commit is contained in:
Taha Tesser
2022-08-16 13:39:05 +03:00
committed by GitHub
parent 3bc49103cc
commit f4a64ef03d
2 changed files with 43 additions and 1 deletions

View File

@@ -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,

View File

@@ -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);
});
}