diff --git a/examples/api/lib/cupertino/list_tile/cupertino_list_tile.0.dart b/examples/api/lib/cupertino/list_tile/cupertino_list_tile.0.dart new file mode 100644 index 00000000000..77178245e90 --- /dev/null +++ b/examples/api/lib/cupertino/list_tile/cupertino_list_tile.0.dart @@ -0,0 +1,65 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +/// Flutter code sample for [CupertinoListTile]. + +void main() => runApp(const CupertinoListTileApp()); + +class CupertinoListTileApp extends StatelessWidget { + const CupertinoListTileApp({super.key}); + + @override + Widget build(BuildContext context) { + return const CupertinoApp( + home: CupertinoListTileExample(), + ); + } +} + +class CupertinoListTileExample extends StatelessWidget { + const CupertinoListTileExample({super.key}); + + @override + Widget build(BuildContext context) { + return CupertinoPageScaffold( + navigationBar: const CupertinoNavigationBar( + middle: Text('CupertinoListTile Sample'), + ), + child: ListView( + children: const [ + CupertinoListTile(title: Text('One-line CupertinoListTile')), + CupertinoListTile( + leading: FlutterLogo(), + title: Text('One-line with leading widget'), + ), + CupertinoListTile( + title: Text('One-line with trailing widget'), + trailing: Icon(Icons.more_vert), + ), + CupertinoListTile( + leading: FlutterLogo(), + title: Text('One-line with both widgets'), + trailing: Icon(Icons.more_vert), + ), + CupertinoListTile( + leading: FlutterLogo(size: 56.0), + title: Text('Two-line CupertinoListTile'), + subtitle: Text('Here is a subtitle'), + trailing: Icon(Icons.more_vert), + additionalInfo: Icon(Icons.info), + ), + CupertinoListTile( + key: Key('CupertinoListTile with background color'), + leading: FlutterLogo(size: 56.0), + title: Text('CupertinoListTile with background color'), + backgroundColor: Colors.lightBlue, + ), + ], + ), + ); + } +} diff --git a/examples/api/test/cupertino/list_tile/cupertino_list_tile.0_test.dart b/examples/api/test/cupertino/list_tile/cupertino_list_tile.0_test.dart new file mode 100644 index 00000000000..2b7d6e39d40 --- /dev/null +++ b/examples/api/test/cupertino/list_tile/cupertino_list_tile.0_test.dart @@ -0,0 +1,32 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/cupertino/list_tile/cupertino_list_tile.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('CupertinoListTile respects properties', (WidgetTester tester) async { + await tester.pumpWidget(const example.CupertinoListTileApp()); + + expect(find.text('CupertinoListTile Sample'), findsOne); + expect(find.byType(CupertinoListTile), findsNWidgets(6)); + + // Verify if the CupertinoListTile contains the expected widgets. + expect(find.byType(FlutterLogo), findsNWidgets(4)); + expect(find.text('One-line with leading widget'), findsOne); + expect(find.text('One-line with trailing widget'), findsOne); + expect(find.text('One-line CupertinoListTile'), findsOne); + expect(find.text('One-line with both widgets'), findsOne); + expect(find.text('Two-line CupertinoListTile'), findsOne); + expect(find.text('Here is a subtitle'), findsOne); + expect(find.text('CupertinoListTile with background color'), findsOne); + expect(find.byIcon(Icons.more_vert), findsNWidgets(3)); + expect(find.byIcon(Icons.info), findsOne); + + final Finder tileWithBackgroundFinder = find.byKey(const Key('CupertinoListTile with background color')); + expect(tester.firstWidget(tileWithBackgroundFinder).backgroundColor, Colors.lightBlue); + }); +} diff --git a/packages/flutter/lib/src/cupertino/list_tile.dart b/packages/flutter/lib/src/cupertino/list_tile.dart index b9c3eba4252..aad09f84390 100644 --- a/packages/flutter/lib/src/cupertino/list_tile.dart +++ b/packages/flutter/lib/src/cupertino/list_tile.dart @@ -70,6 +70,13 @@ enum _CupertinoListTileType { base, notched } /// behavior it should not be used for example to toggle the [CupertinoSwitch] /// in the trailing widget. /// +/// {@tool dartpad} +/// This example uses a [ListView] to demonstrate different configurations of +/// [CupertinoListTile]s. +/// +/// ** See code in examples/api/lib/cupertino/list_tile/cupertino_list_tile.0.dart ** +/// {@end-tool} +/// /// See also: /// /// * [CupertinoListSection], an iOS-style list that is a typical container for