text stringlengths 1 474 |
|---|
home: const HomePage(), |
// The [routes] property defines the available named routes |
// and the widgets to build when navigating to those routes. |
routes: { |
detailsPageRouteName: (context) => const DetailsPage(), |
}, |
); |
} |
}<code_end> |
The following sample generates a list of persons using |
mockPersons(). Tapping a person pushes the person’s detail page |
to the Navigator using pushNamed(). |
<code_start> ListView.builder( |
itemCount: mockPersons.length, |
itemBuilder: (context, index) { |
final person = mockPersons.elementAt(index); |
final age = '${person.age} years old'; |
return ListTile( |
title: Text(person.name), |
subtitle: Text(age), |
trailing: const Icon( |
Icons.arrow_forward_ios, |
), |
onTap: () { |
// When a [ListTile] that represents a person is |
// tapped, push the detailsPageRouteName route |
// to the Navigator and pass the person's instance |
// to the route. |
Navigator.of(context).pushNamed( |
detailsPageRouteName, |
arguments: person, |
); |
}, |
); |
}, |
),<code_end> |
Define the DetailsPage widget that displays the details of |
each person. In Flutter, you can pass arguments into the |
widget when navigating to the new route. |
Extract the arguments using ModalRoute.of(): |
<code_start>class DetailsPage extends StatelessWidget { |
const DetailsPage({super.key}); |
@override |
Widget build(BuildContext context) { |
// Read the person instance from the arguments. |
final Person person = ModalRoute.of( |
context, |
)?.settings.arguments as Person; |
// Extract the age. |
final age = '${person.age} years old'; |
return Scaffold( |
// Display name and age. |
body: Column(children: [Text(person.name), Text(age)]), |
); |
} |
}<code_end> |
To create more advanced navigation and routing requirements, |
use a routing package such as go_router.To learn more, check out Navigation and routing.<topic_end> |
<topic_start> |
Manually pop back |
In SwiftUI, you use the dismiss environment value to pop-back to |
the previous screen.In Flutter, use the pop() function of the Navigator class: |
<code_start>TextButton( |
onPressed: () { |
// This code allows the |
// view to pop back to its presenter. |
Navigator.of(context).pop(); |
}, |
child: const Text('Pop back'), |
),<code_end> |
<topic_end> |
<topic_start> |
Navigating to another app |
In SwiftUI, you use the openURL environment variable to open a |
URL to another application.In Flutter, use the url_launcher plugin. |
<code_start> CupertinoButton( |
onPressed: () async { |
await launchUrl( |
Uri.parse('https://google.com'), |
); |
}, |
child: const Text( |
'Open website', |
), |
),<code_end> |
<topic_end> |
<topic_start> |
Themes, styles, and media |
You can style Flutter apps with little effort. |
Styling includes switching between light and dark themes, |
changing the design of your text and UI components, |
and more. This section covers how to style your apps.<topic_end> |
<topic_start> |
Using dark mode |
In SwiftUI, you call the preferredColorScheme() |
function on a View to use dark mode.In Flutter, you can control light and dark mode at the app-level. |
To control the brightness mode, use the theme property |
of the App class: |
<code_start> CupertinoApp( |
theme: CupertinoThemeData( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.