1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00

Flutter 3.24 update, Add CarouselView examples to demo 3 (#2377)

This PR is to include `CarouselView` to M3 demo app.


https://github.com/user-attachments/assets/7db76c06-aa7e-4461-9baa-51fd5c4e6b38



## Pre-launch Checklist

- [x] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [x] I signed the [CLA].
- [x] I read the [Contributors Guide].
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] All existing and new tests are passing.

---------

Co-authored-by: Eric Windmill <ewindmill@google.com>
This commit is contained in:
Qun Cheng
2024-08-06 12:12:50 -07:00
committed by GitHub
parent 5ea363687c
commit 2fc80aae12
6 changed files with 146 additions and 11 deletions

View File

@@ -242,6 +242,7 @@ class Containment extends StatelessWidget {
return const ComponentGroupDecoration(label: 'Containment', children: [
BottomSheetSection(),
Cards(),
Carousels(),
Dialogs(),
Dividers(),
// TODO: Add Lists, https://github.com/flutter/flutter/issues/114006
@@ -2416,6 +2417,65 @@ class _SearchAnchorsState extends State<SearchAnchors> {
}
}
class Carousels extends StatelessWidget {
const Carousels({super.key});
@override
Widget build(BuildContext context) {
return ComponentDecoration(
label: 'Carousel',
tooltipMessage: 'Use CarouselView',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: Text('Uncontained Carousel'),
),
ConstrainedBox(
constraints: const BoxConstraints.tightFor(height: 150),
child: CarouselView(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Theme.of(context).colorScheme.outline),
),
shrinkExtent: 100,
itemExtent: 180,
children: List<Widget>.generate(20, (index) {
return Center(
child: Text('Item $index'),
);
}),
),
),
colDivider,
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: Text('Uncontained Carousel with snapping effect'),
),
ConstrainedBox(
constraints: const BoxConstraints.tightFor(height: 150),
child: CarouselView(
itemSnapping: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Theme.of(context).colorScheme.outline),
),
shrinkExtent: 100,
itemExtent: 180,
children: List<Widget>.generate(20, (index) {
return Center(
child: Text('Item $index'),
);
}),
),
),
],
),
);
}
}
class ComponentDecoration extends StatefulWidget {
const ComponentDecoration({
super.key,

View File

@@ -10,7 +10,7 @@ import 'package:material_3_demo/main.dart';
void main() {
testWidgets('Default main page shows all M3 components', (tester) async {
widgetSetup(tester, 800, windowHeight: 7000);
widgetSetup(tester, 800, windowHeight: 7500);
await tester.pumpWidget(const App());
// Elements on the app bar
@@ -67,6 +67,9 @@ void main() {
expect(find.widgetWithText(Cards, 'Filled'), findsOneWidget);
expect(find.widgetWithText(Cards, 'Outlined'), findsOneWidget);
// Carousels
expect(find.byType(CarouselView), findsNWidgets(2));
// Dialogs
expect(find.widgetWithText(TextButton, 'Show dialog'), findsOneWidget);
expect(find.widgetWithText(TextButton, 'Show full-screen dialog'),