Skip to content

Commit 5555ebe

Browse files
committed
Add code tests.
1 parent fe593e0 commit 5555ebe

File tree

3 files changed

+89
-8
lines changed

3 files changed

+89
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
// #docregion first-second-routes
4+
class FirstRoute extends StatelessWidget {
5+
const FirstRoute({super.key});
6+
7+
@override
8+
Widget build(BuildContext context) {
9+
return CupertinoPageScaffold(
10+
navigationBar: const CupertinoNavigationBar(middle: Text('First Route')),
11+
child: Center(
12+
child: CupertinoButton(
13+
child: const Text('Open route'),
14+
onPressed: () {
15+
// Navigate to second route when tapped.
16+
},
17+
),
18+
),
19+
);
20+
}
21+
}
22+
23+
class SecondRoute extends StatelessWidget {
24+
const SecondRoute({super.key});
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
return CupertinoPageScaffold(
29+
navigationBar: const CupertinoNavigationBar(middle: Text('Second Route')),
30+
child: Center(
31+
child: CupertinoButton(
32+
onPressed: () {
33+
// Navigate back to first route when tapped.
34+
},
35+
child: const Text('Go back!'),
36+
),
37+
),
38+
);
39+
}
40+
}
41+
// #enddocregion first-second-routes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
class FirstRoute extends StatelessWidget {
4+
const FirstRoute({super.key});
5+
6+
@override
7+
Widget build(BuildContext context) {
8+
return CupertinoPageScaffold(
9+
navigationBar: const CupertinoNavigationBar(middle: Text('First Route')),
10+
child: Center(
11+
child: CupertinoButton(
12+
child: const Text('Open route'),
13+
// #docregion first-route-on-pressed
14+
// Within the `FirstRoute` widget:
15+
onPressed: () {
16+
Navigator.push(
17+
context,
18+
CupertinoPageRoute(builder: (context) => const SecondRoute()),
19+
);
20+
},
21+
// #enddocregion first-route-on-pressed
22+
),
23+
),
24+
);
25+
}
26+
}
27+
28+
class SecondRoute extends StatelessWidget {
29+
const SecondRoute({super.key});
30+
31+
@override
32+
Widget build(BuildContext context) {
33+
return CupertinoPageScaffold(
34+
navigationBar: const CupertinoNavigationBar(middle: Text('Second Route')),
35+
child: Center(
36+
child: CupertinoButton(
37+
// #docregion second-route-on-pressed
38+
// Within the SecondRoute widget
39+
onPressed: () {
40+
Navigator.pop(context);
41+
},
42+
// #enddocregion second-route-on-pressed
43+
child: const Text('Go back!'),
44+
),
45+
),
46+
);
47+
}
48+
}

src/content/cookbook/navigation/navigation-basics.md

-8
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,6 @@ class SecondRoute extends StatelessWidget {
322322

323323
{% endtabs %}
324324

325-
326-
:::secondary
327-
You don't need to replace all Material widgets with Cupertino versions
328-
to use [`CupertinoPageRoute`][]
329-
since Flutter allows you to mix and match Material and Cupertino widgets
330-
depending on your needs.
331-
:::
332-
333325
## Additional navigation methods
334326

335327
The recipe in this topic shows you one way to navigate to a new screen and

0 commit comments

Comments
 (0)