Skip to content

Commit 7242ea2

Browse files
authored
Actually add example templates (#111531)
1 parent 841e158 commit 7242ea2

File tree

6 files changed

+268
-0
lines changed

6 files changed

+268
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// This is a template file for illustrating best practices when creating a
6+
// Flutter API example that uses the Cupertino library. To use it, copy the file
7+
// to your destination filename, search/replace 'Placeholder' with the name of
8+
// the class this is an example for, delete this block, and implement your
9+
// example.
10+
//
11+
// The name and location of this file should be:
12+
//
13+
// examples/api/lib/<library>/<filename_without_dart>/<lower_snake_symbol>.<index>.dart
14+
//
15+
// So, if your example is the third example of the Foo.bar function in the
16+
// "baz.dart" file in the cupertino library, then the filename for your example
17+
// should be:
18+
//
19+
// examples/api/lib/cupertino/baz/foo_bar.2.dart
20+
//
21+
// and its associated test should be in:
22+
//
23+
// examples/api/test/cupertino/baz/foo_bar.2_test.dart
24+
//
25+
// The following doc comment should remain, and be a doc comment so that the
26+
// symbol will be linked in the IDE. Don't use the whole description of the
27+
// example, since that should already be in the API docs where this example is
28+
// referenced, and we don't want the two descriptions to diverge. If this sample
29+
// is referenced more than once, link back to the instance the example file is
30+
// named for.
31+
32+
/// Flutter code sample for [Placeholder].
33+
34+
import 'package:flutter/cupertino.dart';
35+
36+
void main() {
37+
runApp(const SampleApp());
38+
}
39+
40+
class SampleApp extends StatelessWidget {
41+
const SampleApp({super.key});
42+
@override
43+
Widget build(BuildContext context) {
44+
return const CupertinoApp(
45+
home: PlaceholderExample(),
46+
);
47+
}
48+
}
49+
50+
/// Include comments about each class, and make them dartdoc comments, so that
51+
/// links (e.g. [Placeholder]) are active in IDEs.
52+
class PlaceholderExample extends StatelessWidget {
53+
const PlaceholderExample({super.key});
54+
55+
@override
56+
Widget build(BuildContext context) {
57+
// Since this is an example, add plenty of comments, explaining things that
58+
// both a newcomer and an experienced user might want to know.
59+
//
60+
// TRY THIS: Prefix things with "TRY THIS" in places in the example that
61+
// might be interesting to modify when exploring what the widget/function
62+
// does.
63+
return const Placeholder();
64+
}
65+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// This is a template file for illustrating best practices when creating a
6+
// Flutter API example that uses the Material library. To use it, copy the file
7+
// to your destination filename, search/replace 'Placeholder' with the name of
8+
// the class this is an example for, delete this block, and implement your
9+
// example.
10+
//
11+
// The name and location of this file should be:
12+
//
13+
// examples/api/lib/<library>/<filename_without_dart>/<lower_snake_symbol>.<index>.dart
14+
//
15+
// So, if your example is the third example of the Foo.bar function in the
16+
// "baz.dart" file in the material library, then the filename for your example
17+
// should be:
18+
//
19+
// examples/api/lib/material/baz/foo_bar.2.dart
20+
//
21+
// and its associated test should be in:
22+
//
23+
// examples/api/test/material/baz/foo_bar.2_test.dart
24+
//
25+
// The following doc comment should remain, and be a doc comment so that the
26+
// symbol will be linked in the IDE. Don't use the whole description of the
27+
// example, since that should already be in the API docs where this example is
28+
// referenced, and we don't want the two descriptions to diverge. If this sample
29+
// is referenced more than once, link back to the instance the example file is
30+
// named for.
31+
32+
/// Flutter code sample for [Placeholder].
33+
34+
import 'package:flutter/material.dart';
35+
36+
void main() {
37+
runApp(const SampleApp());
38+
}
39+
40+
class SampleApp extends StatelessWidget {
41+
const SampleApp({super.key});
42+
@override
43+
Widget build(BuildContext context) {
44+
return const MaterialApp(
45+
home: Scaffold(
46+
body: PlaceholderExample(),
47+
),
48+
);
49+
}
50+
}
51+
52+
/// Include comments about each class, and make them dartdoc comments, so that
53+
/// links (e.g. [Placeholder]) are active in IDEs.
54+
class PlaceholderExample extends StatelessWidget {
55+
const PlaceholderExample({super.key});
56+
57+
@override
58+
Widget build(BuildContext context) {
59+
// Since this is an example, add plenty of comments, explaining things that
60+
// both a newcomer and an experienced user might want to know.
61+
//
62+
// TRY THIS: Prefix things with "TRY THIS" in places in the example that
63+
// might be interesting to modify when exploring what the widget/function
64+
// does.
65+
return const Placeholder();
66+
}
67+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// This is a template file for illustrating best practices when creating a
6+
// Flutter API example that uses the Widgets library. To use it, copy the file
7+
// to your destination filename, search/replace 'Placeholder' with the name of
8+
// the class this is an example for, delete this block, and implement your
9+
// example.
10+
//
11+
// The name and location of this file should be:
12+
//
13+
// examples/api/lib/<library>/<filename_without_dart>/<lower_snake_symbol>.<index>.dart
14+
//
15+
// So, if your example is the third example of the Foo.bar function in the
16+
// "baz.dart" file in the widgets library, then the filename for your example
17+
// should be:
18+
//
19+
// examples/api/lib/widgets/baz/foo_bar.2.dart
20+
//
21+
// and its (required) associated test should be in:
22+
//
23+
// examples/api/test/widgets/baz/foo_bar.2_test.dart
24+
//
25+
// The following doc comment should remain, and be a doc comment so that the
26+
// symbol will be linked in the IDE. Don't use the whole description of the
27+
// example, since that should already be in the API docs where this example is
28+
// referenced, and we don't want the two descriptions to diverge. If this sample
29+
// is referenced more than once, link back to the instance the example file is
30+
// named for.
31+
32+
/// Flutter code sample for [Placeholder].
33+
34+
import 'package:flutter/widgets.dart';
35+
36+
void main() {
37+
runApp(const SampleApp());
38+
}
39+
40+
class SampleApp extends StatelessWidget {
41+
const SampleApp({super.key});
42+
@override
43+
Widget build(BuildContext context) {
44+
return WidgetsApp(
45+
color: const Color(0xffffffff),
46+
home: const PlaceholderExample(),
47+
);
48+
}
49+
}
50+
51+
/// Include comments about each class, and make them dartdoc comments, so that
52+
/// links (e.g. [Placeholder]) are active in IDEs.
53+
class PlaceholderExample extends StatelessWidget {
54+
const PlaceholderExample({super.key});
55+
56+
@override
57+
Widget build(BuildContext context) {
58+
// Since this is an example, add plenty of comments, explaining things that
59+
// both a newcomer and an experienced user might want to know.
60+
//
61+
// TRY THIS: Prefix things with "TRY THIS" in places in the example that
62+
// might be interesting to modify when exploring what the widget/function
63+
// does.
64+
return const Placeholder();
65+
}
66+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
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:flutter/cupertino.dart';
6+
import 'package:flutter_api_samples/sample_templates/cupertino.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
// This is an example of a test for API example code.
10+
//
11+
// It only tests that the example is presenting what it is supposed to, but you
12+
// should also test the basic functionality of the example to make sure that it
13+
// functions as expected.
14+
15+
void main() {
16+
testWidgets('Example app has a placeholder', (WidgetTester tester) async {
17+
await tester.pumpWidget(
18+
const example.SampleApp(),
19+
);
20+
21+
expect(find.byType(Placeholder), findsOneWidget);
22+
});
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
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:flutter/material.dart';
6+
import 'package:flutter_api_samples/sample_templates/material.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
// This is an example of a test for API example code.
10+
//
11+
// It only tests that the example is presenting what it is supposed to, but you
12+
// should also test the basic functionality of the example to make sure that it
13+
// functions as expected.
14+
15+
void main() {
16+
testWidgets('Example app has a placeholder', (WidgetTester tester) async {
17+
await tester.pumpWidget(
18+
const example.SampleApp(),
19+
);
20+
21+
expect(find.byType(Scaffold), findsOneWidget);
22+
expect(find.byType(Placeholder), findsOneWidget);
23+
});
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
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:flutter/widgets.dart';
6+
import 'package:flutter_api_samples/sample_templates/widgets.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
// This is an example of a test for API example code.
10+
//
11+
// It only tests that the example is presenting what it is supposed to, but you
12+
// should also test the basic functionality of the example to make sure that it
13+
// functions as expected.
14+
15+
void main() {
16+
testWidgets('Example app has a placeholder', (WidgetTester tester) async {
17+
await tester.pumpWidget(
18+
const example.SampleApp(),
19+
);
20+
21+
expect(find.byType(Placeholder), findsOneWidget);
22+
});
23+
}

0 commit comments

Comments
 (0)