Skip to content

Commit 41b464a

Browse files
authored
[material_ui] Main example (flutter#12336)
This PR creates a main example to appear on pub at https://pub.dev/packages/material_ui/example. It is simply a list of buttons that open some of our existing examples that might be useful for someone that's new to the package. ## How to review Most files were generated by running `flutter create .` inside the example/ directory (to make it a runnable example). The only files you really need to review are: * example/lib/main.dart * example/test/widget_test.dart
1 parent fc22143 commit 41b464a

61 files changed

Lines changed: 3490 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/material_ui/example/.metadata‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,42 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: "89172fc6152056af222e0afcf6e2d6ee4e9f6f8f"
8-
channel: "master"
7+
revision: "5495b6f0c197ad1c40208cce7d4e0283b644b79b"
8+
channel: "layers-example-material_ui"
99

10-
project_type: package
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
17+
base_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
18+
- platform: android
19+
create_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
20+
base_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
21+
- platform: ios
22+
create_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
23+
base_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
24+
- platform: linux
25+
create_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
26+
base_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
27+
- platform: macos
28+
create_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
29+
base_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
30+
- platform: web
31+
create_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
32+
base_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
33+
- platform: windows
34+
create_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
35+
base_revision: 5495b6f0c197ad1c40208cce7d4e0283b644b79b
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'

‎packages/material_ui/example/lib/floating_action_button/floating_action_button.1.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class FloatingActionButtonExample extends StatelessWidget {
3838
//
3939
// https://m3.material.io/components/floating-action-button/specs#669a1be8-7271-48cb-a74d-dd502d73bda4
4040
FloatingActionButton.small(
41+
heroTag: 'small',
4142
onPressed: () {
4243
// Add your onPressed code here!
4344
},
@@ -54,6 +55,7 @@ class FloatingActionButtonExample extends StatelessWidget {
5455
//
5556
// https://m3.material.io/components/floating-action-button/specs#71504201-7bd1-423d-8bb7-07e0291743e5
5657
FloatingActionButton(
58+
heroTag: 'regular',
5759
onPressed: () {
5860
// Add your onPressed code here!
5961
},
@@ -70,6 +72,7 @@ class FloatingActionButtonExample extends StatelessWidget {
7072
//
7173
// https://m3.material.io/components/floating-action-button/specs#9d7d3d6a-bab7-47cb-be32-5596fbd660fe
7274
FloatingActionButton.large(
75+
heroTag: 'large',
7376
onPressed: () {
7477
// Add your onPressed code here!
7578
},
@@ -86,6 +89,7 @@ class FloatingActionButtonExample extends StatelessWidget {
8689
//
8790
// https://m3.material.io/components/extended-fab/specs#686cb8af-87c9-48e8-a3e1-db9da6f6c69b
8891
FloatingActionButton.extended(
92+
heroTag: 'extended',
8993
onPressed: () {
9094
// Add your onPressed code here!
9195
},
Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:material_ui/material_ui.dart';
6+
7+
import 'app_bar/app_bar.1.dart' as app_bar_1;
8+
import 'badge/badge.0.dart' as badge_0;
9+
import 'button_style/button_style.0.dart' as button_style_0;
10+
import 'floating_action_button/floating_action_button.1.dart'
11+
as floating_action_button_1;
12+
import 'icon_button/icon_button.3.dart' as icon_button_3;
13+
import 'segmented_button/segmented_button.0.dart' as segmented_button_0;
14+
import 'card/card.2.dart' as card_2;
15+
import 'carousel/carousel.0.dart' as carousel_0;
16+
import 'checkbox/checkbox.1.dart' as checkbox_1;
17+
import 'action_chip/action_chip.0.dart' as action_chip_0;
18+
import 'choice_chip/choice_chip.0.dart' as choice_chip_0;
19+
import 'filter_chip/filter_chip.0.dart' as filter_chip_0;
20+
import 'input_chip/input_chip.0.dart' as input_chip_0;
21+
import 'date_picker/show_date_picker.0.dart' as show_date_picker_0;
22+
import 'time_picker/show_time_picker.0.dart' as show_time_picker_0;
23+
import 'dialog/alert_dialog.1.dart' as alert_dialog_1;
24+
import 'divider/divider.1.dart' as divider_1;
25+
import 'list_tile/list_tile.2.dart' as list_tile_2;
26+
import 'progress_indicator/linear_progress_indicator.0.dart'
27+
as linear_progress_indicator_0;
28+
import 'progress_indicator/circular_progress_indicator.0.dart'
29+
as circular_progress_indicator_0;
30+
import 'dropdown_menu/dropdown_menu.1.dart' as dropdown_menu_1;
31+
import 'navigation_bar/navigation_bar.1.dart' as navigation_bar_1;
32+
import 'navigation_rail/navigation_rail.0.dart' as navigation_rail_0;
33+
import 'navigation_drawer/navigation_drawer.0.dart' as navigation_drawer_0;
34+
import 'radio/radio.1.dart' as radio_1;
35+
import 'search_anchor/search_anchor.0.dart' as search_anchor_0;
36+
import 'bottom_sheet/show_modal_bottom_sheet.2.dart'
37+
as show_modal_bottom_sheet_2;
38+
import 'slider/slider.0.dart' as slider_0;
39+
import 'range_slider/range_slider.0.dart' as range_slider_0;
40+
import 'snack_bar/snack_bar.2.dart' as snack_bar_2;
41+
import 'switch/switch.2.dart' as switch_2;
42+
import 'tabs/tab_bar.0.dart' as tab_bar_0;
43+
import 'text_field/text_field.2.dart' as text_field_2;
44+
import 'tooltip/tooltip.0.dart' as tooltip_0;
45+
46+
void main() {
47+
runApp(ExampleApp());
48+
}
49+
50+
class ExampleApp extends StatelessWidget {
51+
ExampleApp({super.key});
52+
53+
static const title = 'Material Examples';
54+
55+
final _examples = <_Example>[
56+
_Example(
57+
filepath: 'app_bar/app_bar.1.dart',
58+
title: 'App bars',
59+
builder: (BuildContext context) => const app_bar_1.AppBarApp(),
60+
),
61+
_Example(
62+
filepath: 'badge/badge.0.dart',
63+
title: 'Badges',
64+
builder: (BuildContext context) => const badge_0.BadgeExampleApp(),
65+
),
66+
_Example(
67+
filepath: 'button_style/button_style.0.dart',
68+
title: 'Common buttons',
69+
builder: (BuildContext context) => const button_style_0.ButtonApp(),
70+
),
71+
_Example(
72+
filepath: 'floating_action_button/floating_action_button.1.dart',
73+
title: 'Floating action buttons',
74+
builder: (BuildContext context) =>
75+
const floating_action_button_1.FloatingActionButtonExampleApp(),
76+
),
77+
_Example(
78+
filepath: 'icon_button/icon_button.3.dart',
79+
title: 'Icon buttons',
80+
builder: (BuildContext context) =>
81+
const icon_button_3.IconButtonToggleApp(),
82+
),
83+
_Example(
84+
filepath: 'segmented_button/segmented_button.0.dart',
85+
title: 'Segmented buttons',
86+
builder: (BuildContext context) =>
87+
const segmented_button_0.SegmentedButtonApp(),
88+
),
89+
_Example(
90+
filepath: 'card/card.2.dart',
91+
title: 'Cards',
92+
builder: (BuildContext context) => const card_2.CardExamplesApp(),
93+
),
94+
_Example(
95+
filepath: 'carousel/carousel.0.dart',
96+
title: 'Carousel',
97+
builder: (BuildContext context) => const carousel_0.CarouselExampleApp(),
98+
),
99+
_Example(
100+
filepath: 'checkbox/checkbox.1.dart',
101+
title: 'Checkbox',
102+
builder: (BuildContext context) => const checkbox_1.CheckboxExampleApp(),
103+
),
104+
_Example(
105+
filepath: 'action_chip/action_chip.0.dart',
106+
title: 'Assist chip',
107+
builder: (BuildContext context) => const action_chip_0.ChipApp(),
108+
),
109+
_Example(
110+
filepath: 'choice_chip/choice_chip.0.dart',
111+
title: 'Single select filter chip',
112+
builder: (BuildContext context) => const choice_chip_0.ChipApp(),
113+
),
114+
_Example(
115+
filepath: 'filter_chip/filter_chip.0.dart',
116+
title: 'Multiple select filter chip',
117+
builder: (BuildContext context) => const filter_chip_0.ChipApp(),
118+
),
119+
_Example(
120+
filepath: 'input_chip/input_chip.0.dart',
121+
title: 'Input chip',
122+
builder: (BuildContext context) => const input_chip_0.ChipApp(),
123+
),
124+
_Example(
125+
filepath: 'date_picker/show_date_picker.0.dart',
126+
title: 'Date pickers',
127+
builder: (BuildContext context) =>
128+
const show_date_picker_0.DatePickerApp(),
129+
),
130+
_Example(
131+
filepath: 'time_picker/show_time_picker.0.dart',
132+
title: 'Time pickers',
133+
builder: (BuildContext context) =>
134+
const show_time_picker_0.ShowTimePickerApp(),
135+
),
136+
_Example(
137+
filepath: 'dialog/alert_dialog.1.dart',
138+
title: 'Dialogs',
139+
builder: (BuildContext context) =>
140+
const alert_dialog_1.AlertDialogExampleApp(),
141+
),
142+
_Example(
143+
filepath: 'divider/divider.1.dart',
144+
title: 'Divider',
145+
builder: (BuildContext context) => const divider_1.DividerExampleApp(),
146+
),
147+
_Example(
148+
filepath: 'list_tile/list_tile.2.dart',
149+
title: 'Lists',
150+
builder: (BuildContext context) => const list_tile_2.ListTileApp(),
151+
),
152+
_Example(
153+
filepath: 'progress_indicator/linear_progress_indicator.0.dart',
154+
title: 'Linear progress indicators',
155+
builder: (BuildContext context) =>
156+
const linear_progress_indicator_0.ProgressIndicatorExampleApp(),
157+
),
158+
_Example(
159+
filepath: 'progress_indicator/circular_progress_indicator.0.dart',
160+
title: 'Circular progress indicators',
161+
builder: (BuildContext context) =>
162+
const circular_progress_indicator_0.ProgressIndicatorExampleApp(),
163+
),
164+
_Example(
165+
filepath: 'dropdown_menu/dropdown_menu.1.dart',
166+
title: 'Menu',
167+
builder: (BuildContext context) =>
168+
const dropdown_menu_1.DropdownMenuApp(),
169+
),
170+
_Example(
171+
filepath: 'navigation_bar/navigation_bar.1.dart',
172+
title: 'Navigation bar',
173+
builder: (BuildContext context) =>
174+
const navigation_bar_1.NavigationBarApp(),
175+
),
176+
_Example(
177+
filepath: 'navigation_rail/navigation_rail.0.dart',
178+
title: 'Navigation rail',
179+
builder: (BuildContext context) =>
180+
const navigation_rail_0.NavigationRailExampleApp(),
181+
),
182+
_Example(
183+
filepath: 'navigation_drawer/navigation_drawer.0.dart',
184+
title: 'Navigation drawer',
185+
builder: (BuildContext context) =>
186+
const navigation_drawer_0.NavigationDrawerApp(),
187+
),
188+
_Example(
189+
filepath: 'radio/radio.1.dart',
190+
title: 'Radio button',
191+
builder: (BuildContext context) => const radio_1.RadioExampleApp(),
192+
),
193+
_Example(
194+
filepath: 'search_anchor/search_anchor.0.dart',
195+
title: 'Search',
196+
builder: (BuildContext context) => const search_anchor_0.SearchBarApp(),
197+
),
198+
_Example(
199+
filepath: 'bottom_sheet/show_modal_bottom_sheet.2.dart',
200+
title: 'Bottom sheets',
201+
builder: (BuildContext context) =>
202+
const show_modal_bottom_sheet_2.ModalBottomSheetApp(),
203+
),
204+
_Example(
205+
filepath: 'slider/slider.0.dart',
206+
title: 'Sliders',
207+
builder: (BuildContext context) => const slider_0.SliderExampleApp(),
208+
),
209+
_Example(
210+
filepath: 'range_slider/range_slider.0.dart',
211+
title: 'Range sliders',
212+
builder: (BuildContext context) =>
213+
const range_slider_0.RangeSliderExampleApp(),
214+
),
215+
_Example(
216+
filepath: 'snack_bar/snack_bar.2.dart',
217+
title: 'Snackbar',
218+
builder: (BuildContext context) => const snack_bar_2.SnackBarExampleApp(),
219+
),
220+
_Example(
221+
filepath: 'switch/switch.2.dart',
222+
title: 'Switch',
223+
builder: (BuildContext context) => const switch_2.SwitchApp(),
224+
),
225+
_Example(
226+
filepath: 'tabs/tab_bar.0.dart',
227+
title: 'Tabs',
228+
builder: (BuildContext context) => const tab_bar_0.TabBarApp(),
229+
),
230+
_Example(
231+
filepath: 'text_field/text_field.2.dart',
232+
title: 'Text fields',
233+
builder: (BuildContext context) =>
234+
const text_field_2.TextFieldExamplesApp(),
235+
),
236+
_Example(
237+
filepath: 'tooltip/tooltip.0.dart',
238+
title: 'Tooltip',
239+
builder: (BuildContext context) => const tooltip_0.TooltipExampleApp(),
240+
),
241+
];
242+
243+
@override
244+
Widget build(BuildContext context) {
245+
return MaterialApp(
246+
title: title,
247+
home: _ExampleHome(examples: _examples),
248+
routes: <String, WidgetBuilder>{
249+
for (_Example example in _examples) example.url: example.builder,
250+
},
251+
);
252+
}
253+
}
254+
255+
class _ExampleHome extends StatelessWidget {
256+
const _ExampleHome({required this._examples});
257+
258+
final List<_Example> _examples;
259+
260+
@override
261+
Widget build(BuildContext context) {
262+
return Scaffold(
263+
appBar: AppBar(title: const Text(ExampleApp.title)),
264+
body: Center(
265+
child: ListView(
266+
children: _examples
267+
.map((_Example example) => _ExampleListItem(example: example))
268+
.toList(),
269+
),
270+
),
271+
);
272+
}
273+
}
274+
275+
/// One item that opens its example when tapped.
276+
class _ExampleListItem extends StatelessWidget {
277+
const _ExampleListItem({required this._example});
278+
279+
final _Example _example;
280+
281+
@override
282+
Widget build(BuildContext context) {
283+
return ListTile(
284+
onTap: () {
285+
Navigator.of(context).pushNamed(_example.url);
286+
},
287+
title: Text(_example.title),
288+
);
289+
}
290+
}
291+
292+
/// A self-contained Material example.
293+
class _Example {
294+
const _Example({
295+
required this.filepath,
296+
required this.title,
297+
required this.builder,
298+
});
299+
300+
final WidgetBuilder builder;
301+
final String filepath;
302+
final String title;
303+
304+
String get url {
305+
final segments = filepath.split('/');
306+
assert(segments.length == 2);
307+
final directory = segments.first;
308+
final filename = segments.last;
309+
310+
final filenameSegments = filename.split('.');
311+
assert(filenameSegments.length == 3);
312+
final number = filenameSegments[1];
313+
314+
return '/$directory/$filename/$number';
315+
}
316+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flutter/ephemeral

0 commit comments

Comments
 (0)