Implement CupertinoListSection and CupertinoListTile (#78732)
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
// 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.
|
||||
|
||||
// Flutter code sample for base CupertinoListSection and CupertinoListTile.
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
void main() => runApp(const CupertinoListSectionBaseApp());
|
||||
|
||||
class CupertinoListSectionBaseApp extends StatelessWidget {
|
||||
const CupertinoListSectionBaseApp({super.key});
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const CupertinoApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: CupertinoListSection(
|
||||
header: const Text('My Reminders'),
|
||||
children: <CupertinoListTile>[
|
||||
CupertinoListTile(
|
||||
title: const Text('Open pull request'),
|
||||
leading: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: CupertinoColors.activeGreen,
|
||||
),
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
CupertinoPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return const _SecondPage(text: 'Open pull request');
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
CupertinoListTile(
|
||||
title: const Text('Push to master'),
|
||||
leading: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: CupertinoColors.systemRed,
|
||||
),
|
||||
additionalInfo: const Text('Not available'),
|
||||
),
|
||||
CupertinoListTile(
|
||||
title: const Text('View last commit'),
|
||||
leading: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: CupertinoColors.activeOrange,
|
||||
),
|
||||
additionalInfo: const Text('12 days ago'),
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
CupertinoPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return const _SecondPage(text: 'Last commit');
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SecondPage extends StatelessWidget {
|
||||
const _SecondPage({required this.text});
|
||||
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: Text(text),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// 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.
|
||||
|
||||
// Flutter code sample for inset CupertinoListSection and CupertinoListTile.
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
void main() => runApp(const CupertinoListSectionInsetApp());
|
||||
|
||||
class CupertinoListSectionInsetApp extends StatelessWidget {
|
||||
const CupertinoListSectionInsetApp({super.key});
|
||||
|
||||
static const String _title = 'Flutter Code Sample';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const CupertinoApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: CupertinoListSection.insetGrouped(
|
||||
header: const Text('My Reminders'),
|
||||
children: <CupertinoListTile>[
|
||||
CupertinoListTile.notched(
|
||||
title: const Text('Open pull request'),
|
||||
leading: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: CupertinoColors.activeGreen,
|
||||
),
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
CupertinoPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return const _SecondPage(text: 'Open pull request');
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
CupertinoListTile.notched(
|
||||
title: const Text('Push to master'),
|
||||
leading: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: CupertinoColors.systemRed,
|
||||
),
|
||||
additionalInfo: const Text('Not available'),
|
||||
),
|
||||
CupertinoListTile.notched(
|
||||
title: const Text('View last commit'),
|
||||
leading: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
color: CupertinoColors.activeOrange,
|
||||
),
|
||||
additionalInfo: const Text('12 days ago'),
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
onTap: () => Navigator.of(context).push(
|
||||
CupertinoPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return const _SecondPage(text: 'Last commit');
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SecondPage extends StatelessWidget {
|
||||
const _SecondPage({required this.text});
|
||||
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: Text(text),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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_api_samples/cupertino/list_section/list_section_base.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Has exactly 1 CupertinoListSection base widget', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.CupertinoListSectionBaseApp(),
|
||||
);
|
||||
|
||||
final Finder listSectionFinder = find.byType(CupertinoListSection);
|
||||
expect(listSectionFinder, findsOneWidget);
|
||||
|
||||
final CupertinoListSection listSectionWidget = tester.widget<CupertinoListSection>(listSectionFinder);
|
||||
expect(listSectionWidget.type, equals(CupertinoListSectionType.base));
|
||||
});
|
||||
|
||||
testWidgets('CupertinoListSection has 3 CupertinoListTile children', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.CupertinoListSectionBaseApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(CupertinoListTile), findsNWidgets(3));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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_api_samples/cupertino/list_section/list_section_inset.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Has exactly 1 CupertinoListSection inset grouped widget', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.CupertinoListSectionInsetApp(),
|
||||
);
|
||||
|
||||
final Finder listSectionFinder = find.byType(CupertinoListSection);
|
||||
expect(listSectionFinder, findsOneWidget);
|
||||
|
||||
final CupertinoListSection listSectionWidget = tester.widget<CupertinoListSection>(listSectionFinder);
|
||||
expect(listSectionWidget.type, equals(CupertinoListSectionType.insetGrouped));
|
||||
});
|
||||
|
||||
testWidgets('CupertinoListSection has 3 CupertinoListTile children', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const example.CupertinoListSectionInsetApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(CupertinoListTile), findsNWidgets(3));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user