text
stringlengths
1
372
);
},
),
),
);
}
}
class SecondRoute extends StatelessWidget {
const SecondRoute({super.key});
@override
widget build(BuildContext context) {
return scaffold(
appBar: AppBar(
title: const Text('Second route'),
),
body: center(
child: ElevatedButton(
onPressed: () {
navigator.pop(context);
},
child: const Text('Go back!'),
),
),
);
}
}
<code_end>
<topic_end>
<topic_start>
navigation with CupertinoPageRoute
in the previous example you learned how to navigate between screens
using the MaterialPageRoute from material components.
however, in flutter you are not limited to material design language,
instead, you also have access to cupertino (ios-style) widgets.
implementing navigation with cupertino widgets follows the same steps
as when using MaterialPageRoute,
but instead you use CupertinoPageRoute
which provides an iOS-style transition animation.
in the following example, these widgets have been replaced:
this way, the example follows the current iOS design language.
you don’t need to replace all material widgets with cupertino versions
to use CupertinoPageRoute
since flutter allows you to mix and match material and cupertino widgets
depending on your needs.
<code_start>
import 'package:flutter/cupertino.dart';
void main() {
runApp(const CupertinoApp(
title: 'navigation basics',
home: FirstRoute(),
));
}
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: () {
navigator.push(
context,
CupertinoPageRoute(builder: (context) => const SecondRoute()),
);
},
),
),
);
}
}
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: () {
navigator.pop(context);
},
child: const Text('Go back!'),
),
),
);
}
}
<code_end>
<topic_end>
<topic_start>
send data to a new screen
often, you not only want to navigate to a new screen,
but also pass data to the screen as well.
for example, you might want to pass information about