我需要测试下面的代码来检查是否trailingIconButton == null
应该应用某个文本主题。
Text(
type == TileType.org
? orgInfo!.name!
: type == TileType.user
? '${userInfo!.firstName!} ${userInfo!.lastName!}'
: option!.title,
style: type == TileType.org
? Theme.of(context).textTheme.headline5
: type == TileType.user
? Theme.of(context).textTheme.headline6
: option!.trailingIconButton == null
? Theme.of(context).textTheme.bodyText2
: Theme.of(context)
.textTheme
.headline5!
.copyWith(fontSize: 18),
key: const Key('trailingIconButton'),
),
我写的
testWidgets('Creating Custom List (giving custom options)', (tester) async {
await tester.pumpWidget(createCustomListTileUser(
option: Options(
icon: const Icon(Icons.add),
title: 'henlo',
subtitle: 'yesh',
trailingIconButton: null)));
final Text text =
tester.firstWidget(find.byKey(const Key('trailingIconButton')));
//equals bodyText2
expect(text.style!.getTextStyle(),
equals(Theme.of(MockBuildContext()).textTheme.bodyText2));
});