Skip to content

Commit 7f1a604

Browse files
authored
Minor updates to new orientation recipe (#11682)
1 parent d4f7a1e commit 7f1a604

File tree

7 files changed

+66
-62
lines changed

7 files changed

+66
-62
lines changed

examples/cookbook/design/orientation/lib/main.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class OrientationList extends StatelessWidget {
3232
body: OrientationBuilder(
3333
builder: (context, orientation) {
3434
return GridView.count(
35-
// Create a grid with 2 columns in portrait mode, or 3 columns in
36-
// landscape mode.
35+
// Create a grid with 2 columns in portrait mode, or
36+
// 3 columns in landscape mode.
3737
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
38-
// Generate 100 widgets that display their index in the List.
38+
// Generate 100 widgets that display their index in the list.
3939
children: List.generate(100, (index) {
4040
return Center(
4141
child: Text(
4242
'Item $index',
43-
style: Theme.of(context).textTheme.displayLarge,
43+
style: TextTheme.of(context).displayLarge,
4444
),
4545
);
4646
}),

examples/cookbook/lists/grid_lists/lib/main.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ class MyApp extends StatelessWidget {
1919
),
2020
// #docregion GridView
2121
body: GridView.count(
22-
// Create a grid with 2 columns. If you change the scrollDirection to
23-
// horizontal, this produces 2 rows.
22+
// Create a grid with 2 columns.
23+
// If you change the scrollDirection to horizontal,
24+
// this produces 2 rows.
2425
crossAxisCount: 2,
25-
// Generate 100 widgets that display their index in the List.
26+
// Generate 100 widgets that display their index in the list.
2627
children: List.generate(100, (index) {
2728
return Center(
2829
child: Text(
2930
'Item $index',
30-
style: Theme.of(context).textTheme.headlineSmall,
31+
style: TextTheme.of(context).headlineSmall,
3132
),
3233
);
3334
}),

examples/cookbook/testing/widget/orientation_tests/lib/main.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class OrientationList extends StatelessWidget {
3232
body: OrientationBuilder(
3333
builder: (context, orientation) {
3434
return GridView.count(
35-
// Create a grid with 2 columns in portrait mode, or 3 columns in
36-
// landscape mode.
35+
// Create a grid with 2 columns in portrait mode, or
36+
// 3 columns in landscape mode.
3737
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
38-
// Generate 100 widgets that display their index in the List.
38+
// Generate 100 widgets that display their index in the list.
3939
children: List.generate(100, (index) {
4040
return Center(
4141
child: Text(
4242
'Item $index',
43-
style: Theme.of(context).textTheme.displayLarge,
43+
style: TextTheme.of(context).displayLarge,
4444
),
4545
);
4646
}),

examples/cookbook/testing/widget/orientation_tests/test/widget_test.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// #docregion OrientationWidgetTest
2-
1+
// #docregion scaffolding
32
import 'package:flutter/material.dart';
43
import 'package:flutter_test/flutter_test.dart';
54
import 'package:orientation_tests/main.dart';
65

76
void main() {
87
group('Orientation', () {
8+
// #enddocregion scaffolding
99
// #docregion portrait-mode-test
1010
// Check if portrait mode displays correctly.
1111
testWidgets('Displays 2 columns in portrait mode', (tester) async {
@@ -21,15 +21,15 @@ void main() {
2121
await tester.pump();
2222

2323
// Verify initial orientation is portrait.
24-
Orientation orientation =
24+
final orientation =
2525
MediaQuery.of(tester.element(find.byType(OrientationList)))
2626
.orientation;
2727
expect(orientation, Orientation.portrait);
2828

2929
// Verify there are only 2 columns in portrait mode.
3030
final gridViewFinder = find.byType(GridView);
31-
GridView gridView = tester.widget<GridView>(gridViewFinder);
32-
SliverGridDelegateWithFixedCrossAxisCount delegate =
31+
final gridView = tester.widget<GridView>(gridViewFinder);
32+
final delegate =
3333
gridView.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
3434
expect(delegate.crossAxisCount, 2);
3535
});
@@ -50,19 +50,20 @@ void main() {
5050
await tester.pump();
5151

5252
// Verify initial orientation is landscape.
53-
Orientation orientation =
53+
final orientation =
5454
MediaQuery.of(tester.element(find.byType(OrientationList)))
5555
.orientation;
5656
expect(orientation, Orientation.landscape);
5757

5858
// Verify there are only 3 columns in landscape mode.
5959
final gridViewFinder = find.byType(GridView);
60-
GridView gridView = tester.widget<GridView>(gridViewFinder);
61-
SliverGridDelegateWithFixedCrossAxisCount delegate =
60+
final gridView = tester.widget<GridView>(gridViewFinder);
61+
final delegate =
6262
gridView.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
6363
expect(delegate.crossAxisCount, 3);
6464
});
6565
// #enddocregion landscape-mode-test
66+
// #docregion scaffolding
6667
});
6768
}
68-
// #enddocregion OrientationWidgetTest
69+
// #enddocregion scaffolding

src/content/cookbook/design/orientation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ class OrientationList extends StatelessWidget {
111111
body: OrientationBuilder(
112112
builder: (context, orientation) {
113113
return GridView.count(
114-
// Create a grid with 2 columns in portrait mode, or 3 columns in
115-
// landscape mode.
114+
// Create a grid with 2 columns in portrait mode, or
115+
// 3 columns in landscape mode.
116116
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
117-
// Generate 100 widgets that display their index in the List.
117+
// Generate 100 widgets that display their index in the list.
118118
children: List.generate(100, (index) {
119119
return Center(
120120
child: Text(
121121
'Item $index',
122-
style: Theme.of(context).textTheme.displayLarge,
122+
style: TextTheme.of(context).displayLarge,
123123
),
124124
);
125125
}),

src/content/cookbook/lists/grid-lists.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ generate a list of 100 widgets that display their index in the list.
2222
<?code-excerpt "lib/main.dart (GridView)" replace="/^body\: //g"?>
2323
```dart
2424
GridView.count(
25-
// Create a grid with 2 columns. If you change the scrollDirection to
26-
// horizontal, this produces 2 rows.
25+
// Create a grid with 2 columns.
26+
// If you change the scrollDirection to horizontal,
27+
// this produces 2 rows.
2728
crossAxisCount: 2,
28-
// Generate 100 widgets that display their index in the List.
29+
// Generate 100 widgets that display their index in the list.
2930
children: List.generate(100, (index) {
3031
return Center(
3132
child: Text(
3233
'Item $index',
33-
style: Theme.of(context).textTheme.headlineSmall,
34+
style: TextTheme.of(context).headlineSmall,
3435
),
3536
);
3637
}),
@@ -61,15 +62,16 @@ class MyApp extends StatelessWidget {
6162
title: const Text(title),
6263
),
6364
body: GridView.count(
64-
// Create a grid with 2 columns. If you change the scrollDirection to
65-
// horizontal, this produces 2 rows.
65+
// Create a grid with 2 columns.
66+
// If you change the scrollDirection to horizontal,
67+
// this produces 2 rows.
6668
crossAxisCount: 2,
67-
// Generate 100 widgets that display their index in the List.
69+
// Generate 100 widgets that display their index in the list.
6870
children: List.generate(100, (index) {
6971
return Center(
7072
child: Text(
7173
'Item $index',
72-
style: Theme.of(context).textTheme.headlineSmall,
74+
style: TextTheme.of(context).headlineSmall,
7375
),
7476
);
7577
}),

src/content/cookbook/testing/widget/orientation.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ orientation.
1717

1818
This recipe uses the following steps:
1919

20-
1. Create an app that updates the layout of the content, based on the
21-
orientation.
20+
1. Create an app that updates the layout of the content,
21+
based on the orientation.
2222
1. Create an orientation test group.
2323
1. Create a portrait orientation test.
2424
1. Create a landscape orientation test.
@@ -35,8 +35,8 @@ app is in portrait or landscape mode:
3535
flutter create orientation_tests
3636
```
3737

38-
2. Follow the steps in [Update the UI based on orientation][] to set up the
39-
project.
38+
2. Follow the steps in [Update the UI based on orientation][] to
39+
set up the project.
4040

4141
## 2. Create an orientation test group
4242

@@ -46,23 +46,24 @@ group your future orientation tests:
4646
1. In your Flutter project, open `test/widget_test.dart`.
4747
1. Replace the existing contents with the following:
4848

49+
<?code-excerpt "cookbook/testing/widget/orientation_tests/test/widget_test.dart (scaffolding)"?>
4950
```dart title="widget_test.dart"
5051
import 'package:flutter/material.dart';
5152
import 'package:flutter_test/flutter_test.dart';
5253
import 'package:orientation_tests/main.dart';
53-
54+
5455
void main() {
5556
group('Orientation', () {
56-
...
57+
// ···
5758
});
5859
}
5960
```
6061

6162
## 3. Create a portrait orientation test
6263

63-
Add the portrait orientation test to the `Orientation` group. This test makes
64-
sure that the orientation is `portrait` and that only `2` columns of data
65-
appear in the app:
64+
Add the portrait orientation test to the `Orientation` group.
65+
This test makes sure that the orientation is `portrait` and that
66+
only `2` columns of data appear in the app:
6667

6768
1. In `test/widget_test.dart`, replace `...` inside of the `Orientation` group
6869
with the following test:
@@ -83,25 +84,25 @@ appear in the app:
8384
await tester.pump();
8485
8586
// Verify initial orientation is portrait.
86-
Orientation orientation =
87+
final orientation =
8788
MediaQuery.of(tester.element(find.byType(OrientationList)))
8889
.orientation;
8990
expect(orientation, Orientation.portrait);
9091
9192
// Verify there are only 2 columns in portrait mode.
9293
final gridViewFinder = find.byType(GridView);
93-
GridView gridView = tester.widget<GridView>(gridViewFinder);
94-
SliverGridDelegateWithFixedCrossAxisCount delegate =
94+
final gridView = tester.widget<GridView>(gridViewFinder);
95+
final delegate =
9596
gridView.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
9697
expect(delegate.crossAxisCount, 2);
9798
});
9899
```
99100

100101
## 4. Create a landscape orientation test
101102

102-
Add the landscape orientation test to the `Orientation` group. This test makes
103-
sure that the orientation is `landscape` and that only `3` columns of data
104-
appear in the app:
103+
Add the landscape orientation test to the `Orientation` group.
104+
This test makes sure that the orientation is `landscape` and that
105+
only `3` columns of data appear in the app:
105106

106107
1. In `test/widget_test.dart`, inside of the `Orientation` group,
107108
add the following test after the landscape test:
@@ -122,15 +123,15 @@ appear in the app:
122123
await tester.pump();
123124
124125
// Verify initial orientation is landscape.
125-
Orientation orientation =
126+
final orientation =
126127
MediaQuery.of(tester.element(find.byType(OrientationList)))
127128
.orientation;
128129
expect(orientation, Orientation.landscape);
129130
130131
// Verify there are only 3 columns in landscape mode.
131132
final gridViewFinder = find.byType(GridView);
132-
GridView gridView = tester.widget<GridView>(gridViewFinder);
133-
SliverGridDelegateWithFixedCrossAxisCount delegate =
133+
final gridView = tester.widget<GridView>(gridViewFinder);
134+
final delegate =
134135
gridView.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
135136
expect(delegate.crossAxisCount, 3);
136137
});
@@ -148,7 +149,6 @@ flutter test test/widget_test.dart
148149

149150
<?code-excerpt "cookbook/testing/widget/orientation_tests/test/widget_test.dart"?>
150151
```dart title="widget_test.dart"
151-
152152
import 'package:flutter/material.dart';
153153
import 'package:flutter_test/flutter_test.dart';
154154
import 'package:orientation_tests/main.dart';
@@ -169,15 +169,15 @@ void main() {
169169
await tester.pump();
170170
171171
// Verify initial orientation is portrait.
172-
Orientation orientation =
172+
final orientation =
173173
MediaQuery.of(tester.element(find.byType(OrientationList)))
174174
.orientation;
175175
expect(orientation, Orientation.portrait);
176176
177177
// Verify there are only 2 columns in portrait mode.
178178
final gridViewFinder = find.byType(GridView);
179-
GridView gridView = tester.widget<GridView>(gridViewFinder);
180-
SliverGridDelegateWithFixedCrossAxisCount delegate =
179+
final gridView = tester.widget<GridView>(gridViewFinder);
180+
final delegate =
181181
gridView.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
182182
expect(delegate.crossAxisCount, 2);
183183
});
@@ -196,15 +196,15 @@ void main() {
196196
await tester.pump();
197197
198198
// Verify initial orientation is landscape.
199-
Orientation orientation =
199+
final orientation =
200200
MediaQuery.of(tester.element(find.byType(OrientationList)))
201201
.orientation;
202202
expect(orientation, Orientation.landscape);
203203
204204
// Verify there are only 3 columns in landscape mode.
205205
final gridViewFinder = find.byType(GridView);
206-
GridView gridView = tester.widget<GridView>(gridViewFinder);
207-
SliverGridDelegateWithFixedCrossAxisCount delegate =
206+
final gridView = tester.widget<GridView>(gridViewFinder);
207+
final delegate =
208208
gridView.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
209209
expect(delegate.crossAxisCount, 3);
210210
});
@@ -248,15 +248,15 @@ class OrientationList extends StatelessWidget {
248248
body: OrientationBuilder(
249249
builder: (context, orientation) {
250250
return GridView.count(
251-
// Create a grid with 2 columns in portrait mode, or 3 columns in
252-
// landscape mode.
251+
// Create a grid with 2 columns in portrait mode, or
252+
// 3 columns in landscape mode.
253253
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
254-
// Generate 100 widgets that display their index in the List.
254+
// Generate 100 widgets that display their index in the list.
255255
children: List.generate(100, (index) {
256256
return Center(
257257
child: Text(
258258
'Item $index',
259-
style: Theme.of(context).textTheme.displayLarge,
259+
style: TextTheme.of(context).displayLarge,
260260
),
261261
);
262262
}),

0 commit comments

Comments
 (0)