mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[Docs] CupertinoListTile
API Example (#154548)
This PR adds an example for CupertinoListTile Fixes: https://github.com/flutter/flutter/issues/154438
This commit is contained in:
parent
e819a38292
commit
d355a474f9
@ -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 <Widget>[
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -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<CupertinoListTile>(tileWithBackgroundFinder).backgroundColor, Colors.lightBlue);
|
||||
});
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user