-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigate to a new screen and back (add stronger iOS support) (#11776)
_Description of what this PR is changing or adding, and why:_ * Merged the iOS topic at the bottom of the guide into the existing recipe so that a developer can quickly toggle between Android and iOS steps. * Added additional code snippet tests for the iOS samples. _Issues fixed by this PR (if any):_ _PRs or commits this PR depends on (if any):_ ## Presubmit checklist - [x] This PR is marked as draft with an explanation if not meant to land until a future stable release. - [x] This PR doesn’t contain automatically generated corrections (Grammarly or similar). - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer.
- Loading branch information
Showing
3 changed files
with
187 additions
and
35 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
examples/cookbook/navigation/navigation_basics/lib/main_step1_cupertino.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
|
||
// #docregion first-second-routes | ||
class FirstRoute extends StatelessWidget { | ||
const FirstRoute({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar(middle: Text('First Route')), | ||
child: Center( | ||
child: CupertinoButton( | ||
child: const Text('Open route'), | ||
onPressed: () { | ||
// Navigate to second route when tapped. | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class SecondRoute extends StatelessWidget { | ||
const SecondRoute({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar(middle: Text('Second Route')), | ||
child: Center( | ||
child: CupertinoButton( | ||
onPressed: () { | ||
// Navigate back to first route when tapped. | ||
}, | ||
child: const Text('Go back!'), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
// #enddocregion first-second-routes |
48 changes: 48 additions & 0 deletions
48
examples/cookbook/navigation/navigation_basics/lib/main_step2_cupertino.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
|
||
class FirstRoute extends StatelessWidget { | ||
const FirstRoute({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar(middle: Text('First Route')), | ||
child: Center( | ||
child: CupertinoButton( | ||
child: const Text('Open route'), | ||
// #docregion first-route-on-pressed | ||
// Within the `FirstRoute` widget: | ||
onPressed: () { | ||
Navigator.push( | ||
context, | ||
CupertinoPageRoute(builder: (context) => const SecondRoute()), | ||
); | ||
}, | ||
// #enddocregion first-route-on-pressed | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class SecondRoute extends StatelessWidget { | ||
const SecondRoute({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar(middle: Text('Second Route')), | ||
child: Center( | ||
child: CupertinoButton( | ||
// #docregion second-route-on-pressed | ||
// Within the SecondRoute widget | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
// #enddocregion second-route-on-pressed | ||
child: const Text('Go back!'), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters